/**
 *
 * Copyright  2011 Nokia Corporation.
 * tuomo.hirvonen@digia.com
 *
 */


#ifndef __THELEVEL__
#define __THELEVEL__


#include "SpriteBatch.h"


class TheGame;

// level data,
// bit 1, cleared
// bit 2, has mine
// bit 3, marked as minefield
// bits 5-8 = number to display

class TheLevel {
public:
    TheLevel( TheGame *game, int width, int height, int minePercentage );
    ~TheLevel();


    void update( const float frameDelta );
    void render( SpriteBatch *batch, float posx, float posy );

    inline int getWidth() { return width; }
    inline int getHeight() { return height; }
    inline unsigned char *getLevelData() { return levelData; }
    unsigned char getLevelDataAt( int x, int y );

    bool click( float x, float y );
    bool longClick( float x, float y );

    bool isGameOver() { return gameOver; }
    bool isLevelCompleted() { return levelCompleted; }

    inline int getTotalMines() { return totalMines; }
    inline int getTotalMinerMarks() { return mineMarks; }

    void showMap() { showPreviewMap = true; }
    void hideMap() { showPreviewMap = false; }
    bool isShowingMap() { return showPreviewMap; }


protected:
    void resetLevel(int minePercentage, int avoidx, int avoidy);

    bool showPreviewMap;
    float zoomAmount;           // 1 = normal zoom
    int minePercentage;
    int openCount;             // how many tiles have been opened.
    TheGame *game;

    bool flash;
    int totalMines;
    int mineMarks;

    float flashCount;
    bool gameOver;
    bool levelCompleted;
    void openTile( int x, int y);
    void reCalculateTileIndices();


    int width, height;
    unsigned char *levelData;
    unsigned char *levelTiles;
    float *mineMarkAnimationState;

};





#endif
